package com.ivy.wechatforclient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ivy.wechatforclient.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Lenovo on 2017/12/5.
 */

public class ContactAdapter  extends BaseAdapter {
    private Context ctx;
    private List<Map<String, Object>> allValues;


    public ContactAdapter(Context ctx, List<Map<String, Object>> allValues) {
        this.ctx = ctx;
        this.allValues = allValues;
    }
    @Override
    public int getCount() {
        return allValues.size();
    }

    @Override
    public Object getItem(int position) {
        return allValues.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view  = null;
        if(convertView == null) {
            view = LayoutInflater.from(ctx).inflate(R.layout.item_contact, null);

        } else {
            view = convertView;
        }

        ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
        TextView tv_contact_name = (TextView)view.findViewById(R.id.tv_contact_name);

        Map<String, Object> map = allValues.get(position);
       // iv_icon.setImageResource(R.drawable.);
        tv_contact_name.setText(map.get("username").toString());
        return view;
    }
    public void clear() {
        allValues.clear();
        notifyDataSetChanged();
    }
}
